from pathlib import Path
import json
# 定义函数
def input_favorite_num():
    """请示用户输入喜欢的数字,并存储到文件中"""
    while True:
        try:
            num = input("请输入你喜欢的一个数字：")
        except ValueError:
            print("输入类型有误，重新输入：")
            continue
        else:
            path = Path('favorite_num.json')
            favori_num = json.dumps(num)
            path.write_text(favori_num)
            return num

# 定义函数
def read_num():
    """读取文件中的数字"""
    path = Path('favorite_num.json')
    content = input_favorite_num()
    f_num = json.loads(content)
    print(f"I know your favorite number!It's {f_num}")

# 调用函数
read_num()